﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AlgoImpl
{
    public class Converter
    {
        private static int s_Id = 0;

        public void ConvertToGraph(List<string> shifts, List<string> workers, Dictionary<string, List<string>> sr)
        {
            s_Id = 0;
            Graph.Instance.MakeEmpty();
            addWorkersToGraph(workers);
            addShiftsToGraph(shifts);
            connectWorkersToShifts(sr);
        }

        private void connectWorkersToShifts(Dictionary<string, List<string>> sr)
        {
            foreach (KeyValuePair<string, List<string>> kvp in sr)
            {
                addSingleRequest(kvp.Key, kvp.Value);
            }
        }

        private void addSingleRequest(string worker, List<string> list)
        {
            foreach (string shift in list)
            {
                Graph.Instance.AddNeighbourToNode(Graph.Instance.GetNodeIdByDataId(worker), Graph.Instance.GetNodeIdByDataId(shift), 1);
            }
        }

        private void addWorkersToGraph(List<string> workers)
        {
            foreach (string worker in workers)
            {
                Graph.Instance.AddNodeToSide(worker, s_Id.ToString(), eSideInGraph.LEFT);
                s_Id++;
            }
        }

        private void addShiftsToGraph(List<string> shifts)
        {
            foreach (string shift in shifts)
            {
                Graph.Instance.AddNodeToSide(shift, s_Id.ToString(), eSideInGraph.RIGHT);
                s_Id++;
            }
        }

    }
}
